package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Yjzyfwd;
import com.ruoyi.system.service.IYjzyfwdService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Yingjifuwu;
import com.ruoyi.system.service.IYingjifuwuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * YingJiFuWuController
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/system/yingjifuwu")
public class YingjifuwuController extends BaseController
{
    @Autowired
    private IYingjifuwuService yingjifuwuService;
    @Autowired
    private IYjzyfwdService yjzyfwdService;
    /**
     * 查询YingJiFuWu列表
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:list')")
    @GetMapping("/list")
    public TableDataInfo list(Yingjifuwu yingjifuwu)
    {
        startPage();
        List<Yingjifuwu> list = yingjifuwuService.selectYingjifuwuList(yingjifuwu);
        for (Yingjifuwu yingjifuwu1:list
             ) {
            Yjzyfwd yjzyfwd=new Yjzyfwd();
            yjzyfwd.setName(yingjifuwu1.getYjdwmc());
            List<Yjzyfwd> yjzyfwds = yjzyfwdService.selectYjzyfwdList(yjzyfwd);
            if(null!=yjzyfwds&&yjzyfwds.size()>0)
            {
                yingjifuwu1.setYjzyfwd(yjzyfwds.get(0));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出YingJiFuWu列表
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:export')")
    @Log(title = "YingJiFuWu", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Yingjifuwu yingjifuwu)
    {
        List<Yingjifuwu> list = yingjifuwuService.selectYingjifuwuList(yingjifuwu);
        ExcelUtil<Yingjifuwu> util = new ExcelUtil<Yingjifuwu>(Yingjifuwu.class);
        util.exportExcel(response, list, "YingJiFuWu数据");
    }

    /**
     * 获取YingJiFuWu详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Yingjifuwu yingjifuwu = yingjifuwuService.selectYingjifuwuById(id);
        Yjzyfwd yjzyfwd=new Yjzyfwd();
        yjzyfwd.setName(yingjifuwu.getYjdwmc());
        List<Yjzyfwd> yjzyfwds = yjzyfwdService.selectYjzyfwdList(yjzyfwd);
        if(null!=yjzyfwds&&yjzyfwds.size()>0)
        {
            yingjifuwu.setYjzyfwd(yjzyfwds.get(0));
        }
        return success(yingjifuwu);
    }

    /**
     * 新增YingJiFuWu
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:add')")
    @Log(title = "YingJiFuWu", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Yingjifuwu yingjifuwu)
    {
        return toAjax(yingjifuwuService.insertYingjifuwu(yingjifuwu));
    }

    /**
     * 修改YingJiFuWu
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:edit')")
    @Log(title = "YingJiFuWu", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Yingjifuwu yingjifuwu)
    {
        return toAjax(yingjifuwuService.updateYingjifuwu(yingjifuwu));
    }

    /**
     * 删除YingJiFuWu
     */
//    @PreAuthorize("@ss.hasPermi('system:yingjifuwu:remove')")
    @Log(title = "YingJiFuWu", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yingjifuwuService.deleteYingjifuwuByIds(ids));
    }
}
